/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.cosmact.vxml.gefmodel.impl;

import org.cosmact.vxml.gefmodel.*;
import org.cosmact.vxml.gefmodel.GefmodelFactory;
import org.cosmact.vxml.gefmodel.GefmodelPackage;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.impl.EFactoryImpl;
import org.eclipse.emf.ecore.plugin.EcorePlugin;

/**
 * <!-- begin-user-doc --> An implementation of the model <b>Factory</b>. <!--
 * end-user-doc -->
 * @generated
 */
public class GefmodelFactoryImpl extends EFactoryImpl implements
		GefmodelFactory {
	/**
         * Creates the default factory implementation.
         * <!-- begin-user-doc --> <!--
	 * end-user-doc -->
         * @generated
         */
	public static GefmodelFactory init() {
                try {
                        GefmodelFactory theGefmodelFactory = (GefmodelFactory)EPackage.Registry.INSTANCE.getEFactory("gefmodel"); 
                        if (theGefmodelFactory != null) {
                                return theGefmodelFactory;
                        }
                }
                catch (Exception exception) {
                        EcorePlugin.INSTANCE.log(exception);
                }
                return new GefmodelFactoryImpl();
        }

	/**
         * Creates an instance of the factory.
         * <!-- begin-user-doc --> <!--
	 * end-user-doc -->
         * @generated
         */
	public GefmodelFactoryImpl() {
                super();
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	@Override
	public EObject create(EClass eClass) {
                switch (eClass.getClassifierID()) {
                        default:
                                throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
                }
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	@Override
	public Object createFromString(EDataType eDataType, String initialValue) {
                switch (eDataType.getClassifierID()) {
                        case GefmodelPackage.GEF_SIZE:
                                return createGEFSizeFromString(eDataType, initialValue);
                        case GefmodelPackage.GEF_POINT:
                                return createGEFPointFromString(eDataType, initialValue);
                        default:
                                throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier");
                }
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	@Override
	public String convertToString(EDataType eDataType, Object instanceValue) {
                switch (eDataType.getClassifierID()) {
                        case GefmodelPackage.GEF_SIZE:
                                return convertGEFSizeToString(eDataType, instanceValue);
                        case GefmodelPackage.GEF_POINT:
                                return convertGEFPointToString(eDataType, instanceValue);
                        default:
                                throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier");
                }
        }

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public Dimension createGEFSizeFromString(EDataType eDataType,
			String initialValue) {
		return createSizeFromString(eDataType, initialValue);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public String convertGEFSizeToString(EDataType eDataType,
			Object instanceValue) {
		return convertSizeToString(eDataType, instanceValue);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public Point createGEFPointFromString(EDataType eDataType,
			String initialValue) {
		return createLocationFromString(eDataType, initialValue);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public String convertGEFPointToString(EDataType eDataType,
			Object instanceValue) {
		return convertLocationToString(eDataType, instanceValue);
	}

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @generated
         */
	public GefmodelPackage getGefmodelPackage() {
                return (GefmodelPackage)getEPackage();
        }

	/**
         * <!-- begin-user-doc --> <!-- end-user-doc -->
         * @deprecated
         * @generated
         */
	@Deprecated
	public static GefmodelPackage getPackage() {
                return GefmodelPackage.eINSTANCE;
        }

	public String convertLocationToString(EDataType eDataType,
			Object instanceValue) {
		Point p = (Point) instanceValue;
		return p.x + "," + p.y;
	}

	public Point createLocationFromString(EDataType eDataType,
			String initialValue) {
		Point p = new Point();
		String[] values = initialValue.split(",");
		p.x = Integer.parseInt(values[0]);
		p.y = Integer.parseInt(values[1]);
		return p;
	}

	public String convertSizeToString(EDataType eDataType, Object instanceValue) {
		Dimension p = (Dimension) instanceValue;
		return p.width + "," + p.height;
	}

	public Dimension createSizeFromString(EDataType eDataType,
			String initialValue) {
		Dimension p = new Dimension();
		String[] values = initialValue.split(",");
		p.width = Integer.parseInt(values[0]);
		p.height = Integer.parseInt(values[1]);
		return p;
	}

} // GefmodelFactoryImpl
